<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 00. Api范例
 */
class Testde extends Api

{

    // 无需验证登录的方法
    protected $noNeedLogin = ['detest', 'detest1'];

    // 无需要判断权限规则的方法
    protected $noNeedRight = ['*'];

    /**
     * 首页
     *
     * 可以通过@ApiInternal忽略请求的方法
     * @ApiInternal
     */
    public function index()
    {
        return 'index';
    }

    /**
     * 私有方法
     * 私有的方法将不会出现在文档列表
     */
    private function privatetest()
    {
        return 'private';
    }

    /**
     * 测试方法
     *
     * @ApiTitle    样例api
     * @ApiSummary   打个样例格式
     * @ApiMethod (POST)
     *      @ApiRoute (/api/testde/detest)
     *      @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
     * @ApiParams (name="id", type="integer", required=true, description="会员ID")
     * @ApiParams (name="name", type="string", required=true, description="用户名")
     * @ApiParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据")
     *
     *      @ApiReturnParams (name="code", type="integer", required=true, sample="0")
     *      @ApiReturnParams (name="msg", type="string", required=true, sample="返回成功")
     *      @ApiReturnParams (name="data", type="object", sample="{'user_id':'int','user_name':'string','profile':{'email':'string','age':'integer'}}", description="扩展数据返回")
     * @ApiReturn ({ 'code':'1', 'msg':'返回成功', 'data': '' })
     */

    public function detest($id = '', $name = '')
    {
        $this->success("返回成功", $this->request->request());
    }

    /**
     * 测试方法
     *
     * @ApiTitle    样例api
     * @ApiSummary   打个样例格式
     * @ApiMethod (POST)
     * @param string $username  邮箱/手机号
     * @param string $pwd   密码
     * @ApiReturn ( { "code":200, "msg":"返回成功", "data": "" }  { "code":401, "msg":"请登录", "data": "" } { "code":402, "msg":"服务器错误", "data": "" } )
     */

    public function detest1()
    {
        $data = $this->request->post();
        //  登录逻辑    todo

        $res = ['result' => 1, 'data'=> $data ] ;
        $this->success("登录成功", $res );
    }


}
